#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
//枚举对称的数字sqrt(n)再函数判断素数
ll a, b;

bool prime(ll n) {
    if (n == 2)return true;
    if (n < 2 || n % 2 == 0)return false;
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)return false;
    }
    return true;
}
/**
 * 长度为奇数的对称数
 * @param n
 * @return
 */
ll r1(ll n) {//123=>12321
    ll m = n / 10;
    do {
        int d = n % 10;
        m = m * 10 + d;
        n /= 10;
    } while (n > 0);
    return m;
}
/**
 * 长度为偶数的对称数
 * @param n
 * @return
 */
ll r2(ll n) {//123=>123321
    ll m = n;
    do {
        int d = n % 10;
        m = m * 10 + d;
        n /= 10;
    } while (n > 0);
    return m;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    while (cin >> a >> b) {
        vector<ll> ans;
        for (ll i = 1; i <= 1e6 && i <= b; i++) {
            ll j = r1(i), k = r2(i);
            if (j >= a && j <= b && prime(j))ans.push_back(j);
            if (k >= a && k <= b && prime(k))ans.push_back(k);
            if (j > b)break;
        }
        sort(ans.begin(), ans.end());
        for (auto e:ans) {
            cout << e << endl;
        }
        cout << endl;
    }
    return 0;
}
